﻿
using SKeeper.Application.Services.Warehouse;
using SKeeper.Persistence.Facade;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using SKeeper.Application.ViewModels.Warehouse;
using SKeeper.Application.Services;
using SKeeper.Application.InputModels;

namespace SKeeper.Controllers
{
    [Authorize]
    public class WarehouseController : Controller
    {
        private DomainModelFacade db;
        private IWarehouseControllerService warehouseService;
        
        public WarehouseController()
        {
            this.db = new DomainModelFacade();
            this.warehouseService = new WarehouseControllerService(this.db);
        }

        public ActionResult Index(int id = 0)
        {
            var currentUserId = this.User.Identity.GetUserId();
            var viewModel = this.warehouseService.GetWarehouseIndexViewModel(currentUserId, id);
            return View(viewModel);
        }

        public ActionResult Add()
        {
            var viewModel = new CreateWarehouseViewModel
            {
                UserId = this.User.Identity.GetUserId()
            };

            return this.View(viewModel);
        }
        [HttpPost]
        public ActionResult Add(CreateWarehouseViewModel model)
        {
            this.warehouseService.Add(model);
            return this.RedirectToAction("index");
        }



        [HttpPost]
        public ActionResult Filter(ProductsFilterInputModel filter)
        {

            ProductListViewModel model = this.warehouseService.GetProductList(filter);

            return this.PartialView("_ProductList", model);
        }
    }
}